package com.amap.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

import com.amap.R;
import com.amap.model.Place;

public class LocationAdapter extends BaseAdapter{
	
	private Context context;
	private List<Place> places;
	
	public LocationAdapter(Context context, List<Place> places) {
		super();
		this.context = context;
		this.places = places;
	}

	@Override
	public int getCount() {
		return places.size();
	}

	@Override
	public Object getItem(int position) {
		return places.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Place place = places.get(position);
        if (convertView == null) {
        	LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        	convertView = inflater.inflate(R.layout.list_item, null);
        }
        
        TextView placeName = (TextView) convertView.findViewById(R.id.nameLabel);
        placeName.setText(place.getName());
        
        TextView adress = (TextView) convertView.findViewById(R.id.adressLabel);
        adress.setText(place.getAdress());
        
        RatingBar rbar = (RatingBar) convertView.findViewById(R.id.ratingBar1);
        rbar.setRating(place.getRating());
        
		return convertView;
	}

}
